<?php

class model_firadio_php_sys_dwz {

    public $statusCode = "";
    public $message = "";
    public $navTabId = "";
    public $rel = "";
    public $callbackType = "";
    public $forwardUrl = "";
    public $confirmMsg = "";

    public function __construct($ret) {
        if ($ret !== 0) {
            if ($ret > 0) {
                $this->statusCode = 200;
                $this->message = '操作成功！';
            } else {
                $this->statusCode = 300;
                $this->message = '操作失败！错误号：' . $ret;
            }
            switch (app::$MENU_PATH) {
                case('sys_procedure_add'):case('sys_procedure_edit'):case('sys_procedure_del'):
                    $this->navTabId = "sys_procedure_list_" . $_GET['parentid'];
                    break;
            }
            switch (app::$MENU_PATH) {
                case('sys_procedure_add'):case('sys_procedure_edit'):
                    $this->callbackType = "closeCurrent";
                    break;
            }
            $this->printJSON();
            exit;
        }
    }

    public function toArray() {
        return (array) $this;
    }

    public function printJSON() {
        echo json_encode($this->toArray());
    }

    public static function getPageInfo(&$table, &$pageinfo) {
        if (is_numeric($pageinfo))
            return;
        $where = "1";
        //获取记录总数
        $pageinfo['totalCount'] = $table->field("count(menuitem.id) AS totalCount")->where($where, array())->getvalue();
        //获取要查询的页码
        $pageinfo['pageNum'] = (isset($pageinfo['pageNum']) && intval($pageinfo['pageNum']) >= 1) ? $pageinfo['pageNum'] : 1;
        //获取单页最大数量
        $pageinfo['numPerPage'] = (isset($pageinfo['numPerPage']) && intval($pageinfo['numPerPage']) >= 1) ? $pageinfo['numPerPage'] : 15;
        //判断是否超过最大页数
        $maxPageNum = ceil($pageinfo['totalCount'] / $pageinfo['numPerPage']);
        if ($pageinfo['pageNum'] > $maxPageNum)
            $pageinfo['pageNum'] = $maxPageNum;
        return($pageinfo);
    }

}

?>